#include "Config.h"
#include "MsgPool.h"

bool MsgPool::init( UInt8 workerCount )
{
	_workerCount = workerCount;
	m_MsgQueue = new(std::nothrow) MsgQueue[workerCount];
	m_MsgMutex = new(std::nothrow) wch::FastMutex[workerCount];
	return true;
}

void MsgPool::unInit()
{
	for ( UInt8 i = 0; i < _workerCount; ++ i )
	{
		wch::FastMutex::ScopedLock lock( m_MsgMutex[i] );
		while ( !m_MsgQueue[i].Empty() )
		{
			MsgHdr * msg = m_MsgQueue[i].Pop();
			delete[] (char *)msg;
		}
	}
	delete[] m_MsgQueue;
	delete[] m_MsgMutex;
}
